﻿using HDFSViewer.Component;
using HDFSViewer.Enum;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace HDFSViewer.Model
{
    public class HDFSNodeModel : NotifyObject
    {
        public string Name { get; set; }
        public string QueryPath { get; set; }
        public string JoinPath { get; set; }
        public NodeType Type { get; set; }

        public bool IsLoaded { get; set; }

        private bool _isExpended = false;
        public bool IsExpended
        {
            get { return _isExpended; }
            set
            {
                _isExpended = value;
                this.RaisePropertyChanged("IsExpended");
            }
        }

        public HDFSNodeModel Root { get; set; }

        public ObservableCollection<HDFSNodeModel> Childs { get; set; }

        public HDFSNodeModel(NodeType type, string name, string queryPath, HDFSNodeModel root)
            : this()
        {
            this.Type = type;
            this.QueryPath = queryPath;
            this.JoinPath = queryPath == "/" ? string.Empty : queryPath;
            this.Root = root;
            this.Name = name;
        }

        public HDFSNodeModel()
        {
            IsLoaded = false;
            Childs = new ObservableCollection<HDFSNodeModel>();
        }

        public void ExpandAll()
        {
            this.IsExpended = true;
            foreach (var child in Childs)
            {
                child.ExpandAll();
            }
        }

        public void CollapseAll()
        {
            this.IsExpended = false;
            foreach (var child in Childs)
            {
                child.CollapseAll();
            }
        }
    }
}
